package com.szmirren.vxApi.spi.handler.impl;

import com.szmirren.vxApi.core.entity.VxApis;
import com.szmirren.vxApi.spi.handler.VxApiAfterHandler;

import io.vertx.core.AsyncResult;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

/**
 * 后置处理器处理示例
 *
 * @author <a href="http://szmirren.com">Mirren</a>
 */
public class TestAfterHandlerSimple implements VxApiAfterHandler {
    private VxApis apis;
    private JsonObject options;
    private HttpClient httpClient;

    @Override
    public void handle(RoutingContext event) {
        // 这里得到主处理器的执行结果后可以做一些相应的处理,处理完毕后响应请求
        AsyncResult<Boolean> result = event.<AsyncResult<Boolean>>get(PREV_IS_SUCCESS_KEY);
        if (result.succeeded()) {
            System.out.println("AfterHandler :　" + apis);
        } else {
            System.out.println("AfterHandler error :　" + result.cause());
        }

        System.out.println("option 配置信息传入：" + options);
        System.out.println("httpClient 传入：" + httpClient);
        event.response().end();

    }

    public TestAfterHandlerSimple(VxApis api) {
        super();
        this.apis = api;
    }

    public TestAfterHandlerSimple(VxApis apis, JsonObject options, HttpClient httpClient) {
        this.apis = apis;
        this.options = options;
        this.httpClient = httpClient;
    }
}
